Skip to content

加载明文模型 - YoloLoadModelEx

函数简介

从磁盘加载明文模型(ONNX / TensorRT Engine / NCNN)。

接口名称

YoloLoadModelEx

DLL 调用

long YoloLoadModelEx(long ola, string modelPath, string ncnnParamPath, string namesLabel, int modelType, int inferenceType, int inferenceDevice);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
modelPath字符串主模型路径:ONNX/Engine 单文件;NCNN 为 .bin
ncnnParamPath字符串NCNN 的 .param 路径;非 NCNN 传空字符串
namesLabel字符串类别名文件(一行一类),可选空
modelType整数型模型后端类型,见下表
inferenceType整数型推理任务类型,见下表
inferenceDevice整数型inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long YoloLoadModelEx(long ola, string modelPath, string ncnnParamPath, string namesLabel, int modelType, int inferenceType, int inferenceDevice);

long instance = CreateCOLAPlugInterFace();
YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)

返回值

长整数型:模型句柄,失败返回 0。

注意事项

  • 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
含义
0TensorRT Engine(.engine)
1ONNX(.onnx)
2NCNN(.bin + .param 双文件)
含义
0Detect 目标检测
1Classify 图像分类
2Segment 实例分割
3Pose 姿态估计
4Obb 旋转框检测
  • inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。
  • 勿传入加密包路径。